# datetime模块下的datetime类
import time
from datetime import datetime

# print(datetime.now())  # 获取当前日期时间对象
# print(type(datetime.now()))
#
# # datetime.fromtimestamp([填入时间戳])  # 将时间戳转换为datetime对象
# times = time.time()
# print(datetime.fromtimestamp(times))

# datetime.strptime(str,fmt) 按照fmt的格式将字符串时间转化为datetime对象时间
datetime_str = '2022-06-1 11:35:35'
datetime_obj = datetime.strptime(datetime_str, '%Y-%m-%d %H:%M:%S')
print(type(datetime_obj), datetime_obj)

# datetime_obj.strftime(fmt) 按照fmt格式将datetime对象时间转化为字符串时间
dt1 = datetime.today()  # datetime对象
print(type(dt1), dt1)
print(dt1.strftime('%Y-%m-%d %H:%M:%S'))
print(type(dt1.strftime('%Y-%m-%d %H:%M:%S')))

